package ro.bluecube.admlocal.gui.commons;

import java.util.Map;

import javax.swing.JDialog;
import javax.swing.JPanel;

public class Utils {

	public static void centerDialogInParent(JDialog dialog, JPanel parent) {

		int parentX = parent.getX();
		int parentY = parent.getY();
		int parentWidth = parent.getWidth();
		int parentHeight = parent.getHeight();

		int centerX = parentWidth / 2 + parentX;
		int centerY = parentHeight / 2 + parentY;

		int dialogX = centerX - dialog.getWidth() / 2;
		int dialogY = centerY - dialog.getHeight() / 2;

		dialog.setBounds(dialogX, dialogY, dialog.getWidth(), dialog
				.getHeight());
	}

	public static String[] FORME_EXAMINARE = { "Examen", "Colocviu","Proiect"};

	public static String getFormaExaminare(int fex) {
		if (fex >= 0 && fex <= FORME_EXAMINARE.length) {
			return FORME_EXAMINARE[fex];
		} else
			return "";
	}

	public static String[] TIPURI_LOC = { "Buget", "Taxa"};
	
	public static String getTipLoc(boolean taxa) {
		if (taxa) return TIPURI_LOC[1];
		return TIPURI_LOC[0];
	}

	public static boolean getTipLocBoolean(int index) {
		return index==0?false:true;
	}
	public static int getTipLocInt(boolean tl) {
		return tl?1:0;
	}

	public static void activateController(AbstractController parent,
			String className, Map context) {
		Class clazz = null;
		try {
			clazz = Class.forName(className);
			if (clazz != null) {
				try {
					AbstractController controller = ((AbstractController) clazz
							.newInstance());
					controller.setParent(parent);
					controller.activate(context);
				} catch (InstantiationException e1) {
					return;
				} catch (IllegalAccessException e1) {
					return;
				}
			}

		} catch (ClassNotFoundException e1) {
			System.out.println(e1.getMessage());
			return;
		}
	}
}
